package model;

import filter.HttpRequestFilter;
import filter.HttpResponseFilter;
import lombok.Data;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * server总体配置对象
 *
 * @author dsp
 * @date 2021-04-05
 */
@Data
public class HttpConfig {

    private int port = 8888;
    private int workerNum = 16;
    private int maxContentLength = 1024;
    /**
     * 所有的路由信息
     */
    private List<Router> routers;
    private Map<String,Router> routersMap;
    /**
     * 路由对应的活跃节点
     */
    private Map<String/*serverName*/, List<String>/*endpoints*/> serverEndpoints;
    /**
     * 服务端请求过滤器
     */
    private List<HttpRequestFilter> requestFilters;
    /**
     * 服务端相应过滤器
     */
    private List<HttpResponseFilter> responseFilters;

    public void setRouters(List<Router> routers) {
        this.routers = routers;
        this.routersMap = routers.stream()
                .collect(Collectors.toMap(Router::getServerName, Function.identity(),(key1 , key2)-> key2 ));
    }
}
